$(function () {
    var vue = new Vue({
        el: '.login',
        data: {
            phone: '',   // 手机号
            passWord: '',   // 密码
            wordCode: '',   // 图片验证码
            infoCode: '',   // 短信验证码
            newPassWord: '', // 新密码
            registerPassWord : '', // 注册密码
            isLoginShow: 'true'
        },
        methods: {
            // 点击登录，切换到登录模块
            clickLogin: function () {
                $('.login-top ul li').eq(0).addClass('pitch')
                    .siblings().removeClass('pitch')
                    .addClass('not-pitch').end().removeClass('not-pitch');
                this.isLoginShow = 'true'
            },
            // 点击注册，切换到注册模块
            clickRegister: function () {
                $('.login-top ul li').eq(1).addClass('pitch')
                    .siblings().removeClass('pitch')
                    .addClass('not-pitch').end().removeClass('not-pitch');
                this.isLoginShow = 'false'
            },
            // 切换是否能看到密码
            toggleLook: function () {
                if ($('.look img').attr('src') == '../../img/not-look.png') {
                    $('.look img').attr('src','../../img/look.png');
                    $('.pass-word').attr('type','text')
                }
                else {
                    $('.look img').attr('src','../../img/not-look.png');
                    $('.pass-word').attr('type','password')
                }

            },
            // 登录提交
            loginSubmit: function () {
                var _phone = this.phone;
                var _passWord = this.passWord;
                var _wordCode = this.wordCode;
                if (_phone == '') {
                    layer.msg("手机号不能为空");
                    return ;
                }
                else if (_passWord == '') {
                    layer.msg("密码不能为空");
                    return ;
                }
                else if (_wordCode == '') {
                    layer.msg("验证码不能为空");
                    return ;
                }

            },
            // 获取短信验证码
            gainCode: function () {
                var _phone = this.phone;
                var _wordCode = this.wordCode;
                if(_phone.length == ''){
                    layer.msg("手机号不能为空");
                    return;
                }
                else if (!(/^1[3|4|5|7|8][0-9]{9}$/.test(_phone))){
                    layer.msg("手机号错误");
                    return;
                }
                else if ((/^170[0-9]{8}$/.test(_phone))){
                    layer.msg("很抱歉，受服务限制您的手机号无法注册")
                    return;
                }
                else if (_wordCode == '') {
                    layer.msg("验证码不能为空")
                    return;
                }

                // 倒计时
                var time = 60;
                $('.get-code').hide();
                $('.count-down').show();
                $('.count-down span').html(10)
                var iCount = setInterval(function () {
                    if( time > 0) {
                        time --;
                        $('.count-down span').html(time)
                    } else {
                        clearInterval(iCount);
                        $('.get-code').show();
                        $('.count-down').hide();
                    }
                },1000);
            },
            // 注册提交
            registerSubmit: function () {
                var _registerPassWord = this.registerPassWord   ;
                var _infoCode = this.infoCode;
                console.log(_registerPassWord)
                var regEn = /[`~!@#$%^&*()_+<>?:"{},.\/;'[\]]/im,
                    regCn = /[·！#￥（——）：；“”‘、，|《。》？、【】[\]]/im;
                if (_infoCode == '') {
                    layer.msg("短信验证码不能为空");
                    return;
                }
                else if (_registerPassWord.length<6) {
                    layer.msg("密码不能小于6位");
                    return;
                }
                else if (_registerPassWord.length>15) {
                    layer.msg("密码不能大于15位");
                    return;
                }
                else if (regEn.test(_registerPassWord) || regCn.test(_registerPassWord)) {
                    layer.msg("密码不能包含特殊字符");
                    return;
                }
            }
        }
    });
})
